package windowsCursor;

import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

import com.jinvoke.win32.User32;
import com.jinvoke.win32.structs.Point;

import static com.jinvoke.win32.WinConstants.*;


public class myCursor{
	
	static Point cursorPoint = new Point();
	
	public static void pressLeft(){
		User32.mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
	}
	
	public static void pressMiddle(){
		User32.mouse_event(MOUSEEVENTF_MIDDLEDOWN,0,0,0,0);
	}
	
	public static void pressRight(){
		User32.mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
	}
	
	public static void releaseLeft(){
		User32.mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
	}
	
	public static void releaseRight(){
		User32.mouse_event(MOUSEEVENTF_MIDDLEUP,0,0,0,0);
	}
	
	public static void releaseMiddle(){
		User32.mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
	}
	
	public static void moveLeft(){
		User32.mouse_event(MOUSEEVENTF_MOVE,-20,0,0,0);
	}
	
	public static void moveRight(){
		User32.mouse_event(MOUSEEVENTF_MOVE,20,0,0,0);
	}
	
	public static void moveUp(){
		User32.mouse_event(MOUSEEVENTF_MOVE,0,-20,0,0);
	}
	
	public static void moveDown(){
		User32.mouse_event(MOUSEEVENTF_MOVE,0,20,0,0);
	}
	
	public static void scrollUp(){
		User32.mouse_event(MOUSEEVENTF_WHEEL,0,0,-120,0);
	}
	
	public static void scrollDown(){
		User32.mouse_event(MOUSEEVENTF_WHEEL,0,0,120,0);
	}
	
	public static void zoomUp(){
		final byte key = (byte) 0x11;
		final byte reference = (byte) 0x9d;
		User32.keybd_event(key,reference,0,0);
		User32.mouse_event(MOUSEEVENTF_WHEEL,0,0,120,0);
		User32.keybd_event(key,reference, KEYEVENTF_KEYUP, 0);
	}
	
	public static void zoomDown(){
		final byte key = (byte) 0x11;
		final byte reference = (byte) 0x9d;
		User32.keybd_event(key,reference,0,0);
		User32.mouse_event(MOUSEEVENTF_WHEEL,0,0,-120,0);
		User32.keybd_event(key,reference, KEYEVENTF_KEYUP, 0);
	}
	
	public static void position(){
		User32.GetCursorPos(cursorPoint);
		int cursorX = cursorPoint.x;
		int cursorY = cursorPoint.y;
		System.out.println("x: " + cursorPoint.x + "; y: " + cursorPoint.y);
	}
	
	/*public static void main(String args[]){
	
	
	//Scanner scan = new Scanner(System.in);
	//String input;
	
	while(true){
		
		input = scan.nextLine();
		User32.GetCursorPos(cursorPoint);
		cursorX = cursorPoint.x;
		cursorY = cursorPoint.y;
		
		if(input.equals("d")){
			cursorX += 20;
			User32.SetCursorPos(cursorX, cursorY);
		}
		else if(input.equals("a")){
			//cursorX -= 20;
			//User32.SetCursorPos(cursorX, cursorY);
			for(int i =0; i<20; i++){
				User32.mouse_event(MOUSEEVENTF_MOVE,-1,0,0,0);
			}
			//System.out.println("x: " + cursorPoint.x + "; y: " + cursorPoint.y);
		}
		else if(input.equals("s")){
			cursorY += 20;
			User32.SetCursorPos(cursorX, cursorY);
		}
		else if(input.equals("w")){
			cursorY -= 20;
			User32.SetCursorPos(cursorX, cursorY);
		}
		else if(input.equals("k")){
			User32.mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
			User32.mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
		}
		else if(input.equals("j")){
			User32.mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
			User32.mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
		}
		
		else if(input.equals("h")){
			User32.mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
			User32.mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
		}
		
		else if(input.equals("o")){
			User32.mouse_event(MOUSEEVENTF_WHEEL,0,0,-500,0);
		}
		else if(input.equals("l")){
			User32.mouse_event(MOUSEEVENTF_WHEEL,0,0,500,0);
		}//End of if statement
				
	}//End of while statement
	
}//End of main()*/

	/*public static void main(String args[]){
		
		Timer myTimer = new Timer();
		byte input = 0;
		final byte key = (byte) 0x11;
		final byte reference = (byte) 0x9d;
		
		myTimer.schedule(new TimerTask(){
			
			public void run(){			
				
				User32.keybd_event(key,reference,0,0);
				User32.mouse_event(MOUSEEVENTF_WHEEL,0,0,500,0);
				User32.keybd_event(key,reference, KEYEVENTF_KEYUP, 0);
			}
			
		}, 0, 1000);
	}//End of second main();*/
	
}
